import { getProjectInfo } from '../../api/projectInner'
import { baseNetList } from '@/api/innerProject/5gNetManage'

const state = {
  // 具体的项目Id
  projectId: '',
  // 具体项目的信息
  projectName: '',
  projectInfo: {
    projectName: '',
    projectType: '',
    projectCost: '',
    projectAera: '',
    planDate: '',
    planFinDate: '',
    projectMananger: '',
    projectCompletion: '',
    imageList: [],
    figure: '',
    projectInfo: '',
    province: '',
    projectAd: '',
    projectThumAd: '',
    projectMap: '',
    consUnit: '',
    devpUnit: '',
    versionUnit: '',
    designUnit: '',
    surveyUnit: '',
    projectNumber: '',
    createTime: '',
    isCrossfire: ''
  },
  baseNetDTO: []
}

const mutations = {
  // 设置具体的项目id
  set_projectId (state, projectId) {
    state.projectId = projectId
  },
  // 设置具体的项目名称
  set_projectName (state, projectId) {
    state.projectName = projectId
  },
  // 设置具体项目的详细信息
  set_projectInfo (state, obj) {
    state.projectInfo = obj
  },
  // 设置具体项目的详细信息
  set_baseNetDTO (state, list) {
    state.baseNetDTO = list
  }
}

const actions = {
  // 获取具体项目的信息
  getProjectInfo ({ state, commit }, payload) {
    const projectId = localStorage.getItem('projectId') || sessionStorage.getItem('projectId')
    return new Promise((resolve, reject) => {
      getProjectInfo(projectId)
        .then(res => {
          commit('set_projectInfo', res.data.data)
          resolve(res)
        })
        .catch(err => {
          reject(err)
        })
    })
  },
  // 获取5G基站内容列表
  baseNetList ({ state, commit }, payload) {
    const projectId = localStorage.getItem('projectId')
    return new Promise((resolve, reject) => {
      baseNetList(projectId)
        .then(res => {
          commit('set_baseNetDTO', res.data.data)
          resolve(res)
        })
        .catch(err => {
          reject(err)
        })
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
